package vn.sunnet.backviet01.game.coloa.util;

import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class MyButton extends Sprite implements IMenuItem{
	private final int ID;
	private final TextureRegion press;
	private final TextureRegion init;
	
	public MyButton(final int id, float pX, float pY, TextureRegion pTextureRegion, TextureRegion pPress) {
		super(pX, pY, pTextureRegion);
		this.ID = id;
		this.init = pTextureRegion;
		this.press = pPress;
	}
	
	public boolean contains(final float pX, final float pY) {
		if (isVisible())
			return super.contains(pX, pY);
		return false;
	}
	
	public boolean checkPress(float pX, float pY) {
		if (isVisible()) {
			float xPos = getX();
			float yPos = getY();
			if (pX < xPos + getWidth() && pX > xPos && pY < yPos + getHeight() && pY > yPos)
				return true;
		}
		
		return false;
	}
	
	@Override
	public int getID() {
		return ID;
	}

	@Override
	public void onSelected() {
		updateTextureRegion(press);
	}

	@Override
	public void onUnselected() {
		updateTextureRegion(init);
	}
}
